#include "HowToState.h"
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "../SGD Wrappers/SGD_InputManager.h"
#include "../SGD Wrappers/SGD_AudioManager.h"
#include "../SGD Wrappers/SGD_EventManager.h"
#include "../SGD Wrappers/SGD_Event.h"
#include "../SGD Wrappers/SGD_MessageManager.h"
#include "../SGD Wrappers/SGD_Message.h"

#include "Game.h"
#include "MainMenuState.h"
#include <sstream>
#include "Entity.h"
#include "EntityManager.h"
#include "Player.h"
#include "Enemy.h"
#include "MessageID.h"
#include "IncreaseHealthMessage.h"
#include "CreateProjectileMessage.h"
#include "DestroyEntityMessage.h"
#include "FireGrappleMessage.h"
#include "Projectiles.h"
#include "ShadowHook.h"
#include "BitmapFont.h"
#include <cstdlib>
#include "ParticleManager.h"
#include "Lightorb.h"
#include "WorldManager.h"
#include "Zone.h"
#include "BossPlanets.h"
#include "Menu.h"
#include "MenuCursor.h"
#include <vector>
#include <fstream>
#include <sstream>
#include <istream>
#include "../TinyXML/tinyxml.h"
#include "Bullet.h"
#include "Disc.h"
#include "GamePlayState.h"

HowToState* HowToState::GetInstance()
{
	static HowToState instance;
	return &instance;
}


void HowToState::Enter()
{
	SGD::GraphicsManager::GetInstance()->SetClearColor({ 0, 255, 0 });

	//load in XML menu options
	SGD::GraphicsManager::GetInstance()->SetClearColor({ 0, 0, 0 });
	menu = new Menu;
	menu->Initialize("resources/xml/howtoplay.xml");

	//Initialize the Message Manager
	messages = SGD::MessageManager::GetInstance();
	messages->Initialize(&MessageProc);

	//Store the SGD singletons
	audio = SGD::AudioManager::GetInstance();
	graphics = SGD::GraphicsManager::GetInstance();
	input = SGD::InputManager::GetInstance();


	bg = graphics->LoadTexture("resources/images/starfield.png");
	controls = graphics->LoadTexture("resources/images/controlimages.png");

	//initialize entity manager
	entities = new EntityManager;

	font = Game::GetInstance()->GetFont();

	end = 5.0f;

	//Initialize the Particle Manager
	particles = ParticleManager::GetInstance();
	particles->LoadEmitter("resources/xml/Blood2.xml");
	//particles->LoadEmitter("resources/xml/AOEbullet.xml");
	//particles->LoadEmitter("resources/xml/AOEExplode.xml");
	//particles->LoadEmitter("resources/xml/discbullet.xml");
	//particles->LoadEmitter("resources/xml/spike2.xml");

	player = CreatePlayer();
	entities->AddEntity(player, 2);
	GamePlayState::GetInstance()->LoadEmitter(ShadowHook::anchorPoint);
	GamePlayState::GetInstance()->LoadEmitter(ShadowHook::hook);
	//Planets
	Planets* planet1 = new Planets;
	planet1->SetPosition({ 50, 100 });
	planet1->SetSize({ 125, 125 });
	planet1->CalculateRadius();
	planet1->SetPlanetType(Planets::SAND);
	entities->AddEntity(planet1, 0);
	planet1->Release();
}

void HowToState::Exit()
{
	//particles->FreeAllEmitters();
	particles->UnloadEmitter("Blood");
	//particles->UnloadEmitter("AOEBullet");
	//particles->UnloadEmitter("AOEExplode");
	//particles->UnloadEmitter("discbullet");
	//particles->UnloadEmitter("spike");
	particles->FreeAllEmitters();
	particles = nullptr;

	rotateClock = false;
	rotateCounter = false;
	jumped = false;
	grappled = false;
	lightCollected = false;
	enemyKilled = false;
	shaflakKilled = false;
	planetCounter = 1;

	graphics->UnloadTexture(ShadowHook::hook.Flyweight.image);
	graphics->UnloadTexture(ShadowHook::anchorPoint.Flyweight.image);

	player->Release();
	entities->RemoveAll();
	delete entities;
	entities = nullptr;
	graphics->UnloadTexture(bg);
	graphics->UnloadTexture(controls);
	// Terminate & deallocate the SGD wrappers
	messages->Terminate();
	messages = nullptr;
	SGD::MessageManager::DeleteInstance();
	delete menu;
	menu = nullptr;
}

bool HowToState::Input()
{
	if (input->IsAnyKeyPressed()
		|| input->GetMouseMovement() != SGD::Vector{0, 0})
	{
		mkbInput = true;
		controllerInput = false;
	}
	for (int i = 0; i < 32; i++)
	{
		if (input->IsButtonPressed(0, i))
		{
			mkbInput = false;
			controllerInput = true;
		}
	}
	if (input->GetLeftJoystick(0) != SGD::Vector{ 0, 0 } ||
		input->GetRightJoystick(0) != SGD::Vector{ 0, 0 })
	{
		mkbInput = false;
		controllerInput = true;
	}

	if (input->IsKeyPressed(SGD::Key::Escape)
		|| input->IsButtonPressed(0, 1)
		|| end <= 0.0f)
	{
		if (toGame)
		{
			Game::GetInstance()->ChangeState(GamePlayState::GetInstance());
			toGame = false;
		}
		else
			Game::GetInstance()->ChangeState(MainMenuState::GetInstance());
		return true;
	}

	if (input->IsKeyPressed(SGD::Key::A)
		|| input->GetLeftJoystick(0).x < 0)
		rotateCounter = true;
	if (input->IsKeyPressed(SGD::Key::D)
		|| input->GetLeftJoystick(0).x > 0)
		rotateClock = true;

	if (rotateCounter && rotateClock)
	{
		if (input->IsKeyPressed(SGD::Key::Space)
			|| input->IsButtonPressed(0, 0))
		{
			jumped = true;
			if (planetCounter < 2)
				tempPos = player->GetPosition();
		}
	}

	if (jumped)
	{
		if (input->IsKeyPressed(SGD::Key::LButton)
			|| input->GetRightJoystick(0) != SGD::Vector{0,0})
			grappled = true;
	}

	if (grappled)
	{
		if (!lightCollected)
			player->SetCorruption(25.f);
		if (planetCounter > 3 && lOrb->GetSize() == SGD::Size{0,0})
		{
			lightCollected = true;
		}
	}

	if (lightCollected)
	{
		if (planetCounter >= 5 && player->Getenemieskilled() > 0)
			enemyKilled = true;
	}

	return true;
}

void HowToState::Update(float elapsedTime)
{
	if (enemyKilled)
		end -= elapsedTime;
	else
	{
		SGD::Vector d = SGD::Point{ 94.3530045, 72.0639267 } -player->GetRect().ComputeCenter();
		float length = d.ComputeLength();
		if (length > 3000)
		{
			player->SetPosition({ 94.3530045, 72.0639267 });
			player->SetVelocity({ 0, 0 });
		}

		if (player->GetCorruption() > 50)
			player->SetCorruption(25);

		if (rotateCounter && rotateClock)
		{
			if (planetCounter < 2)
			{
				Planets* planetJump = new Planets;
				planetJump->SetPosition({ 400, 75 });
				planetJump->SetSize({ 125, 125 });
				planetJump->CalculateRadius();
				planetJump->SetPlanetType(Planets::SAND);
				entities->AddEntity(planetJump, 0);
				planetJump->Release();
				planetCounter++;
			}
		}

		if (jumped)
		{
			if (planetCounter < 3)
			{
				Planets* planetGrapple = new Planets;
				planetGrapple->SetPosition({ 700, 200 });
				planetGrapple->SetSize({ 125, 125 });
				planetGrapple->CalculateRadius();
				planetGrapple->SetPlanetType(Planets::SAND);
				entities->AddEntity(planetGrapple, 0);
				planetGrapple->Release();
				planetCounter++;
			}
		}

		if (grappled)
		{
			if (planetCounter < 4)
			{
				Planets* planetOrb = new Planets;
				planetOrb->SetPosition({ 1000, 100 });
				planetOrb->SetSize({ 125, 125 });
				planetOrb->CalculateRadius();
				lOrb = CreateLightorb();
				int positionangle = rand() % 361;
				SGD::Point position;
				position.x = float(cos(positionangle) * planetOrb->GetSize().width / 2 + planetOrb->GetRect().ComputeCenter().x - 10);
				position.y = float(sin(positionangle) * planetOrb->GetSize().width / 2 + planetOrb->GetRect().ComputeCenter().y - 10);
				lOrb->SetPosition(position);
				entities->AddEntity(lOrb, 2);
				lOrb->Release();
				planetOrb->SetPlanetType(Planets::SAND);
				entities->AddEntity(planetOrb, 0);
				planetOrb->Release();
				planetCounter++;
			}

			if (lightCollected)
			{
				if (planetCounter < 5)
				{
					Planets* planetEnemy1 = new Planets;
					planetEnemy1->SetPosition({ 1500, 0 });
					planetEnemy1->SetSize({ 125, 125 });
					planetEnemy1->CalculateRadius();
					planetEnemy1->SetPlanetType(Planets::SAND);
					entities->AddEntity(planetEnemy1, 0);
					planetEnemy1->Release();

					Planets* planetEnemy2 = new Planets;
					planetEnemy2->SetPosition({ 2000, -50 });
					planetEnemy2->SetSize({ 125, 125 });
					planetEnemy2->CalculateRadius();
					planetEnemy2->SetPlanetType(Planets::SAND);
					entities->AddEntity(planetEnemy2, 0);
					planetEnemy2->Release();

					Planets* planetEnemy3 = new Planets;
					planetEnemy3->SetPosition({ 2250, 200 });
					planetEnemy3->SetSize({ 125, 125 });
					planetEnemy3->CalculateRadius();
					planetEnemy3->SetPlanetType(Planets::SAND);
					entities->AddEntity(planetEnemy3, 0);
					planetEnemy3->Release();

					Planets* planetEnemy4 = new Planets;
					planetEnemy4->SetPosition({ 2000, 500 });
					planetEnemy4->SetSize({ 125, 125 });
					planetEnemy4->CalculateRadius();
					planetEnemy4->SetPlanetType(Planets::SAND);
					entities->AddEntity(planetEnemy4, 0);
					planetEnemy4->Release();

					Planets* planetEnemy5 = new Planets;
					planetEnemy5->SetPosition({ 1500, 300 });
					planetEnemy5->SetSize({ 125, 125 });
					planetEnemy5->CalculateRadius();
					planetEnemy5->SetPlanetType(Planets::SAND);
					entities->AddEntity(planetEnemy5, 0);
					planetEnemy5->Release();

					Planets* planetEnemy6 = new Planets;
					planetEnemy6->SetPosition({ 1750, 250 });
					planetEnemy6->SetSize({ 125, 125 });
					planetEnemy6->CalculateRadius();
					Enemy * enemy = CreateEnemy();
					int positionangle = rand() % 361;
					SGD::Point position;
					position.x = float(cos(positionangle) * planetEnemy6->GetSize().width / 2 + planetEnemy6->GetRect().ComputeCenter().x);
					position.y = float(sin(positionangle) * planetEnemy6->GetSize().width / 2 + planetEnemy6->GetRect().ComputeCenter().y);
					enemy->SetPosition(position);
					enemy->SetCurrentPlanet(planetEnemy6);
					enemy->SetEType(EType::shabun);
					entities->AddEntity(enemy, 1);
					enemy->Release();
					planetEnemy6->SetPlanetType(Planets::SAND);
					entities->AddEntity(planetEnemy6, 0);
					planetEnemy6->Release();

					planetCounter++;
				}
			}
		}

		graphics->DrawTexture(bg, { 0, -15 });

		messages->Update();

		entities->UpdateAll(elapsedTime);
		entities->CheckCollisions(0, 1);
		entities->CheckCollisions(0, 2);
		entities->CheckCollisions(0, 3);
		entities->CheckCollisions(1, 2);
		entities->CheckCollisions(1, 3);
		entities->CheckCollisions(2, 2);
		entities->CheckCollisions(2, 3);
		entities->CheckCollisions(3, 3);
	}
}

void HowToState::Render()
{
	if (enemyKilled)
	{
		graphics->DrawRectangle({ 0.f, 0.f, float(Game::GetInstance()->GetScreenWidth()), float(Game::GetInstance()->GetScreenHeight()) },
		{ 0, 0, 0 });
		Game::GetInstance()->GetFont()->Draw("LOADING", 25, 25, 1.5f, { 255, 255, 255 });
	}
	else
	{
		SGD::GraphicsManager* graphics = SGD::GraphicsManager::GetInstance();
		if (mkbInput)
		{
			SGD::Rectangle rend{ 78, 96, 153, 169 };
			graphics->DrawTextureSection(controls, { 15 - Game::GetInstance()->GetCameraPos().x,
				235 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
			rend = { 0, 96, 76, 169 };
			graphics->DrawTextureSection(controls, { 15 - Game::GetInstance()->GetCameraPos().x,
				285 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
			graphics->DrawString(
				" to rotate clockwise", { 50 - Game::GetInstance()->GetCameraPos().x,
				250 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			graphics->DrawString(
				" to rotate counter-clockwise", { 50 - Game::GetInstance()->GetCameraPos().x,
				300 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
		}
		else if (controllerInput)
		{
			SGD::Rectangle rend = { 84, 0, 175, 90 };
			graphics->DrawTextureSection(controls, { 15 - Game::GetInstance()->GetCameraPos().x,
				245 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
			graphics->DrawString(
				" tilt right to rotate clockwise", { 50 - Game::GetInstance()->GetCameraPos().x,
				250 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			graphics->DrawString(
				" tilt left to rotate counter-clockwise", { 50 - Game::GetInstance()->GetCameraPos().x,
				275 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
		}

		if (rotateCounter && rotateClock)
		{
			graphics->DrawString(
				"aim for next planet, and press ", { 5 - Game::GetInstance()->GetCameraPos().x,
				0 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			if (mkbInput)
			{
				SGD::Rectangle rend = { 306, 107, 403, 156 };
				graphics->DrawTextureSection(controls, { 300 - Game::GetInstance()->GetCameraPos().x,
					5 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
			}
			else if (controllerInput)
			{
				SGD::Rectangle rend = { 0, 0, 82, 82 };
				graphics->DrawTextureSection(controls, { 300 - Game::GetInstance()->GetCameraPos().x,
					5 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
			}
			graphics->DrawString(
				"to jump toward it ", { 5 - Game::GetInstance()->GetCameraPos().x,
				25 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
		}

		if (jumped)
		{
			if (mkbInput)
			{
				graphics->DrawString(
					"use the mouse to aim toward the next planet", { 400 - Game::GetInstance()->GetCameraPos().x,
					0 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
				graphics->DrawString(
					" to fire your grapple at it, RMB to detach", { 425 - Game::GetInstance()->GetCameraPos().x,
					25 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
				SGD::Rectangle rend = { 1, 175, 70, 269 };
				graphics->DrawTextureSection(controls, { 395 - Game::GetInstance()->GetCameraPos().x,
					20 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
			}
			else if (controllerInput)
			{
				SGD::Rectangle rend = { 176, 0, 267, 90 };
				graphics->DrawTextureSection(controls, { 395 - Game::GetInstance()->GetCameraPos().x,
					20 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
				graphics->DrawString(
					"move this joystick toward planet to fire grapple", { 400 - Game::GetInstance()->GetCameraPos().x,
					0 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			}
		}

		if (grappled)
		{
			if (mkbInput)
			{
				SGD::Rectangle rend = { 230, 86, 305, 168 };
				graphics->DrawTextureSection(controls, { 660 - Game::GetInstance()->GetCameraPos().x,
					330 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
				graphics->DrawString(
					" moves toward the current object", { 700 - Game::GetInstance()->GetCameraPos().x,
					350 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
				rend = { 154, 86, 228, 168 };
				graphics->DrawTextureSection(controls, { 660 - Game::GetInstance()->GetCameraPos().x,
					375 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
				graphics->DrawString(
					" moves away from the current object", { 700 - Game::GetInstance()->GetCameraPos().x,
					375 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			}
			else if (controllerInput)
			{
				SGD::Rectangle rend = { 84, 0, 175, 90 };
				graphics->DrawTextureSection(controls, { 660 - Game::GetInstance()->GetCameraPos().x,
					330 - Game::GetInstance()->GetCameraPos().y }, rend, 0.0f, {}, {}, { .5f, .5f });
				graphics->DrawString(
					" tilt up moves toward the current object", { 700 - Game::GetInstance()->GetCameraPos().x,
					350 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
				graphics->DrawString(
					" tilt down moves away from the current object", { 700 - Game::GetInstance()->GetCameraPos().x,
					375 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			}
			graphics->DrawString(
				"Collect light orbs to cure corruption", { 1000 - Game::GetInstance()->GetCameraPos().x,
				250 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			graphics->DrawString(
				"(that purple stuff on your health bar)", { 1000 - Game::GetInstance()->GetCameraPos().x,
				275 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
		}

		if (lightCollected)
		{
			graphics->DrawString(
				"Using what you've learned, crash into the enemy", { 1000 - Game::GetInstance()->GetCameraPos().x,
				50 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
			graphics->DrawString(
				"in the center and kill it", { 1000 - Game::GetInstance()->GetCameraPos().x,
				75 - Game::GetInstance()->GetCameraPos().y }, SGD::Color{ 255, 255, 255 });
		}

		entities->RenderAll();

		font->Draw(" to exit", 50, (Game::GetInstance()->GetScreenHeight() - 50), 1.f, { 255, 255, 255, 255 });
		if (mkbInput)
		{
			SGD::Rectangle rend{ 0, 272, 74, 346 };
			graphics->DrawTextureSection(controls, { 15, (Game::GetInstance()->GetScreenHeight() - 50.0f) }, rend, 0.0f, {}, {}, { .5f, .5f });
		}
		else if (controllerInput)
		{
			SGD::Rectangle rend{ 76, 271, 158, 354 };
			graphics->DrawTextureSection(controls, { 15, (Game::GetInstance()->GetScreenHeight() - 50.0f) }, rend, 0.0f, {}, {}, { .5f, .5f });
		}
	}
}

void HowToState::MessageProc(const SGD::Message* pMsg)
{
#pragma warning( push )
#pragma warning( 1 : 4061 )

	switch (pMsg->GetMessageID())
	{
	case MessageID::MSG_INCREASE_HEALTH:
	{
										   HowToState::GetInstance()->player->SetHealth(
											   HowToState::GetInstance()->player->GetHealth() + 1);
	}
		break;
	case MessageID::MSG_CREATE_PROJECTILE:
	{
											 const CreateProjectileMessage* proj =
												 dynamic_cast<const CreateProjectileMessage*>(pMsg);
											 Entity* projectile = HowToState::GetInstance()->
												 CreateProjectile(dynamic_cast<Enemy*>(proj->GetOwner()), proj->GetData());
											 HowToState::GetInstance()->entities->AddEntity(projectile, 3);
											 projectile->Release();
	}
		break;
	case MessageID::MSG_FIRE_GRAPPLE:
	{
										const FireGrappleMessage* proj =
											dynamic_cast<const FireGrappleMessage*>(pMsg);
										Entity* shadowGrapple = HowToState::GetInstance()->
											FireGrapple(proj->GetOwner());
										HowToState::GetInstance()->entities->AddEntity(shadowGrapple, 3);
										shadowGrapple->Release();
	}
		break;
	case MessageID::MSG_DESTROY_ENTITY:
	{
										  const DestroyEntityMessage* destMsg =
											  dynamic_cast<const DestroyEntityMessage*>(pMsg);
										  Entity* ptr = destMsg->GetEntity();
										  HowToState::GetInstance()->entities->RemoveEntity(ptr);
	}
		break;
	}

#pragma warning( pop )
}

Player* HowToState::CreatePlayer()
{
	Player* p = new Player;
	TiXmlDocument doc;
	doc.LoadFile("resources/xml/Player.xml");
	TiXmlElement*root = doc.RootElement();
	TiXmlElement*ats = root->FirstChildElement();
	p->SetHealth((float)atof(ats->Attribute("hp")));
	ats = ats->NextSiblingElement();
	p->SetCorruption((float)atof(ats->Attribute("c")));
	ats = ats->NextSiblingElement();//sprite
	ats = ats->NextSiblingElement();
	p->SetSize({ (float)atof(ats->Attribute("w")), (float)atof(ats->Attribute("h")) });
	p->SetPosition({ 94.3530045, 72.0639267 });
	ats = ats->NextSiblingElement();
	p->SetCurrentState(this);
	return p;
}

Enemy* HowToState::CreateEnemy()
{
	Enemy* e = new Enemy(player);
	TiXmlDocument doc;
	doc.LoadFile("resources/xml/ShaBun.xml");
	TiXmlElement*root = doc.RootElement();
	TiXmlElement*ats = root->FirstChildElement();
	ats = ats->NextSiblingElement();
	e->SetSize({ (float)atof(ats->Attribute("w")), (float)atof(ats->Attribute("h")) });
	e->SetPosition({ 200, 200 });
	ats = ats->NextSiblingElement();
	return e;
}

Entity* HowToState::CreateProjectile(Enemy* owner, void*data) const
{
	Projectiles* p;
	if (owner->GetEType() == shaflak)
		p = new Bullet("AOEBullet", "AOEExplode");
	else if (owner->GetEType() == shadisc)
		p = new Disc("discbullet");
	else
		p = new Projectiles;
	p->SetSize({ 5, 5 });
	p->CalculateRadius();
	p->SetOwner(owner);
	p->SetPosition(owner->GetRect().ComputeCenter());
	SGD::Vector toTarget;
	if (owner->GetEType() == shike)
		toTarget = owner->GetRect().ComputeCenter() - owner->GetCurrentPlanet()->GetRect().ComputeCenter();
	else if (owner->GetEType() == shadisc)
		toTarget = *((SGD::Point*)data) - owner->GetRect().ComputeCenter();
	else
		toTarget = owner->GetPlayer()->GetRect().ComputeCenter() - p->GetRect().ComputeCenter();
	toTarget.Normalize();
	toTarget *= 200;
	p->SetVelocity(toTarget);
	SGD::Event e = { "ENEMYFIRE" };
	e.SendEventNow(nullptr);
	return p;
}

Planets* HowToState::CreatePlanet()
{
	TiXmlDocument doc;
	doc.LoadFile("resources/xml/Planet(template).xml");
	TiXmlElement*root = doc.RootElement();
	TiXmlElement*ats = root->FirstChildElement();
	const char * image = ats->GetText();
	Planets*temp = new Planets();
	string help = "resources/images/";
	help += image;
	temp->SetPosition(player->GetPosition());
	return temp;
}

Entity* HowToState::FireGrapple(Entity* owner)
{
	ShadowHook* p = new ShadowHook;
	p->SetSize({ 5, 5 });
	p->CalculateRadius();
	p->SetOwner(owner);
	p->SetPosition(owner->GetPosition());
	Player* pl = dynamic_cast<Player*>(owner);
	SGD::Point point;
	SGD::Vector toMouse;
	if (pl->GetControllerGrapple())
	{
		toMouse = pl->GetControllerVector();
		pl->SetControllerGrapple(false);
	}
	else
	{
		point = { input->GetMousePosition().x,
			input->GetMousePosition().y };
		toMouse = point - (SGD::Point{ (owner->GetPosition().x - Game::GetInstance()->GetCameraPos().x) * Game::GetInstance()->GetZoomLevel(),
			(owner->GetPosition().y - Game::GetInstance()->GetCameraPos().y) * Game::GetInstance()->GetZoomLevel() });
	}
	toMouse.Normalize();
	toMouse *= 600;
	p->SetVelocity(toMouse);
	p->SetChains();
	return p;
}

Lightorb* HowToState::CreateLightorb()
{
	Lightorb* o = new Lightorb();
	o->SetSize({ 16, 16 });
	o->SetPosition({ 200, 200 });
	return o;
}